package com.os;

/**
 * @Author Matt
 * @Date 2022-05-06
 * @Desc:
 * @Version V1.0
 */

import com.os.config.AuthorSettings;
//import com.os.spring_boot_start_hello.service.HelloService;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.descriptor.web.SecurityCollection;
import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统主入口
 */
@SpringBootApplication
//开启定时任务
//@EnableScheduling
//开启异步调用
@EnableAsync
//支持xml配置文件
//@ImportResource（{"classpath:some-context.xml"})

@RestController
public class App {

    @Autowired
    private AuthorSettings authorSettings;

    @Value("${book.author}")
    private String bookAuthor;

    @Value("${book.name}")
    private String bookName;

    @RequestMapping("/")
    String index(){
        return "book name is: " + bookName + " and book author is: " + bookAuthor;
    }

    @RequestMapping("/getAuthorInfo")
    String getAuthorInfo(){
        return "author name is: " + authorSettings.getName() + " and author age is: " + authorSettings.getAge();
    }

//    @Autowired
//    HelloService helloService;
//
//    @RequestMapping("/helloService")
//    public String helloService(){
//        return helloService.sayHello();
//    }

    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(App.class);
        app.run(args);
        //SpringApplication.run(App.class, args);
    }

    /*@Bean
    public EmbeddedServletContainerFactory servletContainerFactory(){
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){
            @Override
            protected void postProcessContext(Context context){
                SecurityConstraint securityConstraint = new SecurityConstraint();
                securityConstraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                securityConstraint.addCollection(collection);
                context.addConstraint(securityConstraint);
            }
        };
        tomcat.addAdditionalTomcatConnectors(httpConnector());
        return tomcat;
    }*/

    /*
    @Bean
    public Connector httpConnector(){
        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        connector.setRedirectPort(8888);
        return connector;
    }
    */

}
